package ccnu.agile.command.verlocitygeneric;

import ccnu.agile.bean.exception.CAPDException;
import ccnu.agile.enums.PrivError;

/**
 * @Description: 模板生成命令执行类
 * @Author: JreamY
 * @Date: 2021/11/14
 **/
public class VelocityGenericInvoker {

    private String className;

    private IGenericCommand command;

    private boolean check;

    public VelocityGenericInvoker(String className, IGenericCommand command) {
        this.className = className;
        this.command = command;
        this.check = true;
    }

    public VelocityGenericInvoker update(IGenericCommand command) {

        if(check) {
            throw new CAPDException(PrivError.GENERIC_CHECK_STATUS_ERROR);
        }

        this.command = command;
        this.check = true;
        return this;
    }

    public VelocityGenericInvoker execute() {
        if(!check) {
            throw new CAPDException(PrivError.GENERIC_CHECK_STATUS_ERROR);
        }

        check = false;
        this.command.execute(className);
        return this;
    }
}
